package com.disgnpattern.learn.chapter2;

/**
 * @author dxy
 * @version 1.0
 * @date 2021/10/21 14:51
 * @decripton 上下文
 */
public class CashContext {
    private CashSuper cs;

    public CashContext(String type) {
        switch (type) {
            case "不打折":
                cs = new CashNormal();
            case "满300减100":
                cs = new CashReturn(300d, 100d);
            case "打8折":
                cs = new CashRebate(0.8d);
        }
        this.cs = cs;
    }

    public double getResult(Double money) {
        return cs.acceptCash(money);
    }
}
